package com.patents.controller;

import com.alibaba.fastjson.JSON;
import com.patents.dao.AdminMapper;
import com.patents.dao.UsersMapper;
import com.patents.pojo.Admin;
import com.patents.pojo.Patents;
import com.patents.pojo.QueryInfo;
import com.patents.pojo.Users;
import com.patents.service.AdminService;
import com.patents.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
@RestController
@CrossOrigin
public class AdminController {
    @Autowired
    AdminMapper adminMapper;
    @Autowired
    @Qualifier("AdminServiceImpl")
    public AdminService adminService;

    @RequestMapping("/AdminLogin")
    public String login(@RequestBody Admin admin) {
        String flag = "error";
        System.out.println("Admin:" + admin);
        Admin us = adminMapper.getAdminByMassage(admin.getAdminname(),admin.getAdminpassword(),admin.getAdmincode());
        HashMap<String, Object> res = new HashMap<>();
        if (us != null) {
            flag = "ok";
        }
        res.put("flag",flag);
        res.put("Admin" ,admin);
        String res_json = JSON.toJSONString(res);
        return res_json;
    }

    @RequestMapping("/CheckPatentList")
    public String getPatentList() {
        System.out.println("访问成功");
        HashMap<String, Object> data = new HashMap<>();
        List<Patents> PatentsList = adminMapper.getPatentB();
        System.out.println(PatentsList);
        data.put("groups", PatentsList);
        String g = JSON.toJSONString(data);
        return g;
    }

    @RequestMapping("/tianjia")
    public String tianjiaPatent(int id) {
        System.out.println("访问成功&&&&&&&&&"+id);
        Patents patents = adminMapper.getCheckPatent(id);
        System.out.println("%%%%%%%%%%%:"+patents);
        adminMapper.addPatent(patents);
        adminMapper.deletePatentById(id);
        return "ok";
    }

    @RequestMapping("/deleteId")
    public String delPatent(int id) {
        adminMapper.deletePatentById(id);
        return "ok";
    }

}
